#include<stdio.h>
#include<unistd.h>
#include<pthread.h>

pthread_mutex_t mutex;
pthread_cond_t cond;
void* p1(void* arg)
{
	int count = 0;
	while(1)
	{
		if(count == 5)
		{
			pthread_cancel(*(pthread_t*)arg);
			break;
		}
		pthread_cond_wait(&cond,&mutex);
		printf("t1活动中...\n");
		count++;
	}
	return NULL;
}
void* p2(void* arg)
{
	while(1)
	{
		pthread_cond_signal(&cond);
		printf("t2 唤醒了 t1...\n");
		sleep(1);
	}
	return NULL;
}
int main()
{
	pthread_t t1,t2;
	pthread_mutex_init(&mutex,NULL);
	pthread_cond_init(&cond,NULL);

	pthread_create(&t1,NULL,p1,&t2);
	pthread_create(&t2,NULL,p2,NULL);

	pthread_join(t1,NULL);
	pthread_join(t2,NULL);

	pthread_mutex_destroy(&mutex);
	pthread_cond_destroy(&cond);
	return 0;
}
